package com.migu.spms.constant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

import com.migu.spms.utils.exception.ServiceException;

public abstract class FlowOperateMapping {
	//按钮对应的排序
	private static Map<String,Integer> buttonSortByKey=new HashMap<String, Integer>();
	//序列对应的按钮
	private static Map<Integer,String> buttonSortByValue=new HashMap<Integer,String>();

	public static String[] genFlowOperateByStatus(String statusCode) {
		List<String> operateList = new ArrayList<String>();
		switch (statusCode) {
		case Constant.flowStatus.NEWING:
			operateList.add(Constant.flowOperate.DEVELOPING);
			operateList.add(Constant.flowOperate.REVERSE);
			break;
		case Constant.flowStatus.DEVELOPING:
			operateList.add(Constant.flowOperate.TRANFER_TEST);
			operateList.add(Constant.flowOperate.REVERSE);
			break;
		case Constant.flowStatus.TRANFER_TEST:
			operateList.add(Constant.flowOperate.TESTING);
			operateList.add(Constant.flowOperate.REVERSE);
			break;
		case Constant.flowStatus.TESTING:
			operateList.add(Constant.flowOperate.IMPLEMENTED);
			operateList.add(Constant.flowOperate.REOPEN);
			operateList.add(Constant.flowOperate.REVERSE);
			break;
		case Constant.flowStatus.REOPEN:
			operateList.add(Constant.flowOperate.TRANFER_TEST);
			operateList.add(Constant.flowOperate.REVERSE);
			break;

		default:
			break;
		}

		return operateList.toArray(new String[operateList.size()]);
	}
	
	public static String getChineseStatus(String statusCode){
		String chineseStatus="";
		switch (statusCode) {
		case Constant.flowStatus.NEWING:
			chineseStatus="新建中";
			break;
		case Constant.flowStatus.DEVELOPING:
			chineseStatus="开发中";
			break;
		case Constant.flowStatus.TRANFER_TEST:
			chineseStatus="转测试";
			break;
		case Constant.flowStatus.TESTING:
			chineseStatus="测试中";
			break;
		case Constant.flowStatus.REOPEN:
			chineseStatus="重新打开";
			break;
		case Constant.flowStatus.IMPLEMENTED:
			chineseStatus="已实现";
			break;
		default:
			break;
		}
		return chineseStatus;
	}
	
	public static String getChineseOperate(String operate){
		String chineseOperate="";
		switch (operate) {
		case Constant.flowOperate.CREATE_NEW_REQUIREMENT:
			chineseOperate="创建新需求";
			break;
		case Constant.flowOperate.DEVELOPING:
			chineseOperate="开发需求";
			break;
		case Constant.flowOperate.TRANFER_TEST:
			chineseOperate="需求转测试";
			break;
		case Constant.flowOperate.TESTING:
			chineseOperate="测试需求";
			break;
		case Constant.flowOperate.IMPLEMENTED:
			chineseOperate="实现需求";
			break;
		case Constant.flowOperate.REOPEN:
			chineseOperate="重新打开需求";
			break;
		case Constant.flowOperate.REVERSE:
			chineseOperate="转交需求";
			break;
		case Constant.flowOperate.EDIT:
			chineseOperate="编辑需求";
			break;
		case Constant.flowOperate.CREAT_BASE_LINE:
			chineseOperate="更新需求基线";
			break;
		default:
			break;
		}
		return chineseOperate;
	}
	
	
	public static List<String> sortButtons(TreeSet<String> buttonsTree){
		TreeSet<Integer> indexByButton=new TreeSet<Integer>();
		Iterator<String> buttonsTreeIterator=buttonsTree.iterator();
		while(buttonsTreeIterator.hasNext()){
			String key=buttonsTreeIterator.next();
			if(!buttonSortByKey.containsKey(key)){
				new ServiceException("按钮集合中没有包含改key"+key);
			}
			Integer index=buttonSortByKey.get(key);
			indexByButton.add(index);
		}
		List<String> indexBySort=new ArrayList<String>();
		Iterator<Integer> indexButtonsIterator=indexByButton.iterator();
		while(indexButtonsIterator.hasNext()){
			String buttonInteger=buttonSortByValue.get(indexButtonsIterator.next());
			indexBySort.add(buttonInteger);
		}
		return indexBySort;
		
	}
	
    static{
    	buttonSortByKey.put(Constant.AccessControl.EDITOR, 1);
    	buttonSortByKey.put(Constant.AccessControl.CREATE_SUB_REQUIRE, 2);
    	buttonSortByKey.put(Constant.AccessControl.MOVE_REQUIRE, 3);
    	buttonSortByKey.put(Constant.AccessControl.UPDATE_BASELINE_VERSION, 4);
    	buttonSortByKey.put(Constant.AccessControl.UPDATE_SCHEDUL_INFO, 5);
    	buttonSortByKey.put(Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO, 6);//测试排期 2017-08-01
    	buttonSortByKey.put(Constant.AccessControl.ADD_COMMENTS, 7);
    	buttonSortByKey.put(Constant.AccessControl.DELETE_REQUIRE, 8);
    	
    	buttonSortByValue.put(1, Constant.AccessControl.EDITOR);
    	buttonSortByValue.put(2, Constant.AccessControl.CREATE_SUB_REQUIRE);
    	buttonSortByValue.put(3, Constant.AccessControl.MOVE_REQUIRE);
    	buttonSortByValue.put(4, Constant.AccessControl.UPDATE_BASELINE_VERSION);
    	buttonSortByValue.put(5, Constant.AccessControl.UPDATE_SCHEDUL_INFO);
    	buttonSortByValue.put(6, Constant.AccessControl.UPDATE_TEST_SCHEDUL_INFO);//测试排期 2017-08-01
    	buttonSortByValue.put(7, Constant.AccessControl.ADD_COMMENTS);
    	buttonSortByValue.put(8, Constant.AccessControl.DELETE_REQUIRE);
    }
	
}
